#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,x,n) for(int i = x; i < n; i++)
#define fr(i,x,n) for(int i = n - 1; i >= x; i--)
#define pb push_back
#define pf push_front
#define mod 998244353
#define endl '\n'
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef long double ld;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int main(){
fast_io
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ll n, a, x, y, m, k;
cin >> n >> a >> x >> y >> m >> k;
vll A(n + 1), pref(n + 1, 0);
A[1] = a;
pref[1] = a;
f(i,2,n + 1){
A[i] = (A[i - 1] * x + y) % m;
pref[i] = (pref[i - 1] + A[i]) % mod;
}
vector <vll> dp(n + 1, vll (k + 1, 0));
dp[1][0] = A[1];
dp[1][1] = A[1];
f(i,2,n + 1){
f(j,0,k + 1){
if(j == 0) dp[i][j] = pref[i];
else{
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1] + (j == 1 ? A[i] : 0)) % mod;
}
}
}
// b[1] = 0;
// b[2] = 8;
// b[3] = 24 + 19 = 43
// b[4] = 48 + 57 + 41 = 146
ll ans = 0;
f(i,1,n + 1){
ans ^= i * dp[i][k];
}
cout << ans << endl;
return 0;
}
162. Find Peak Element | 1529A - Eshag Loves Big Arrays |
19. Remove Nth Node From End of List | 925. Long Pressed Name |
1051. Height Checker | 695. Max Area of Island |
402. Remove K Digits | 97. Interleaving String |
543. Diameter of Binary Tree | 124. Binary Tree Maximum Path Sum |
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts | 501A - Contest |
160A- Twins | 752. Open the Lock |
1535A - Fair Playoff | 1538F - Interesting Function |
1920. Build Array from Permutation | 494. Target Sum |
797. All Paths From Source to Target | 1547B - Alphabetical Strings |
1550A - Find The Array | 118B - Present from Lena |
27A - Next Test | 785. Is Graph Bipartite |
90. Subsets II | 1560A - Dislike of Threes |
36. Valid Sudoku | 557. Reverse Words in a String III |
566. Reshape the Matrix | 167. Two Sum II - Input array is sorted |